package com.gdut.simple.view.fragment;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.gdut.simple.R;
import com.gdut.simple.basic.BasicApplication;
import com.gdut.simple.common.ToastUtils;
import com.gdut.simple.data.entity.User;
import com.gdut.simple.view.basic.AbsBasicFragment;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import cn.bmob.v3.BmobQuery;
import cn.bmob.v3.exception.BmobException;
import cn.bmob.v3.listener.FindListener;
import de.hdodenhof.circleimageview.CircleImageView;

public class UserInfoFragment extends AbsBasicFragment {

    private User user;

    @BindView(R.id.id_user_gender)
    TextView mUserGender;
    @BindView(R.id.id_user_birthday)
    TextView mUserBirthday;
    @BindView(R.id.id_user_area)
    TextView mUserArea;
    @BindView(R.id.id_user_intro)
    TextView mUserIntro;
    @BindView(R.id.id_user_site)
    TextView mUserSite;

    public static UserInfoFragment newInstance(User user) {
        UserInfoFragment userInfoFragment = new UserInfoFragment();
        Bundle bundle = new Bundle();
        bundle.putParcelable("user", user);
        userInfoFragment.setArguments(bundle);
        return userInfoFragment;
    }

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        user = getArguments().getParcelable("user");
    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_user_intro, container, false);
        ButterKnife.bind(this, view);
        return view;
    }

    @Override
    public void fetchData() {
        if (user != null) {
            setConfig(user);
        }
    }

    private void setConfig(User user) {
        mUserGender.setText(user.getGender());
        mUserBirthday.setText(user.getBirthday());
        mUserArea.setText(user.getArea());
        mUserIntro.setText(user.getIntro());
        mUserSite.setText(user.getSite());
    }
}
